home *** CD-ROM | disk | FTP | other *** search
- Path: isonews.bbn.hp.com!hpbblb!news
- From: Matthias Dittrich <matti>
- Newsgroups: comp.lang.c
- Subject: Re: (no subject)
- Date: 28 Feb 1996 08:17:07 GMT
- Organization: Hewlett-Packard Co.
- Message-ID: <4h1323$5es@hpbblb.bbn.hp.com>
- References: <4gv493$p09@nuacht.iol.ie>
- NNTP-Posting-Host: trabant.bbn.hp.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1N (X11; I; HP-UX A.09.07 9000/712)
- X-URL: news:4gv493$p09@nuacht.iol.ie
-
- Roy Leonard <rleonard@ferrotec.ie> wrote:
- >
- >Hi all,
- >
- >I have a strange problem from an embedded system. I have an array of
- >data, and
- >I want to count all the high bits (=1) in the array.
- >
- >Hopefully there is a way I can do this in C at high speed. The
- >alternative is assembler, which I would prefer not to do, but I may have
- >to. Does anyone have any nifty ideas about how I might go about this?
- >
- >
- >The data is of fixed length (roughly 50 long ints). Each bit is evenly
- >weighted.
- >Eg.
- >
- >If the data in binary was "1001001", the total I'm looking for is three.
- >
- >
- If you have a byte array and enough space, it is possible to create
- an array of length 256, each field contains the number of high bits
- of the corresponding index (i.e. high[0]=0, high[1]=1, high[2]=1,
- high[3]=2,...)
- The count of all high bits in the array is the sum of high bits of each
- byte. I think this is fast.
-
- Good luck,
- Matthias
-
-